Passed
Pull Request — master (#22)
by
unknown
04:46
created

WaveFile.fromALaw   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
// Type definitions for wavefile 11.0
2
// Project: https://github.com/rochars/wavefile
3
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars>
4
// Definitions: https://github.com/rochars/wavefile
5
6
export = wavefile;
7
8
declare module wavefile {
9
  class WaveFile {
10
    /**
11
     * The bit depth code according to the samples.
12
     * @type {string}
13
     */
14
    bitDepth: string;
15
    /**
16
     * The container identifier.
17
     * 'RIFF', 'RIFX' and 'RF64' are supported.
18
     * @type {string}
19
     */
20
    container: string;
21
    /**
22
     * @type {number}
23
     */
24
    chunkSize: number;
25
    /**
26
     * The format.
27
     * Always 'WAVE'.
28
     * @type {string}
29
     */
30
    format: string;
31
    /**
32
     * The data of the 'fmt' chunk.
33
     * @type {!Object<string, *>}
34
     */
35
    fmt: object;
36
    /**
37
     * The data of the 'fact' chunk.
38
     * @type {!Object<string, *>}
39
     */
40
    fact: object;
41
    /**
42
     * The data of the 'cue ' chunk.
43
     * @type {!Object<string, *>}
44
     */
45
    cue: object;
46
    /**
47
     * The data of the 'smpl' chunk.
48
     * @type {!Object<string, *>}
49
     */
50
    smpl: object;
51
    /**
52
     * The data of the 'bext' chunk.
53
     * @type {!Object<string, *>}
54
     */
55
    bext: object;
56
    /**
57
     * The data of the 'mext' chunk.
58
     * @type {!Object<string, *>}
59
     */
60
    mext: object;
61
    /**
62
     * The data of the 'cart' chunk.
63
     * @type {!Object<string, *>}
64
     */
65
    cart: object;
66
    /**
67
     * The data of the 'iXML' chunk.
68
     * @type {!Object<string, *>}
69
     */
70
    iXML: object;
71
    /**
72
     * The data of the 'ds64' chunk.
73
     * Used only with RF64 files.
74
     * @type {!Object<string, *>}
75
     */
76
    ds64: object;
77
    /**
78
     * The data of the 'data' chunk.
79
     * @type {!Object<string, *>}
80
     */
81
    data: object;
82
    /**
83
     * The data of the 'LIST' chunks.
84
     * Each item in this list look like this:
85
     *  {
86
     *    chunkId: '',
87
     *    chunkSize: 0,
88
     *    format: '',
89
     *    subChunks: []
90
     *   }
91
     * @type {!Array<!Object>}
92
     */
93
    LIST: object[];
94
    /**
95
     * The data of the 'junk' chunk.
96
     * @type {!Object<string, *>}
97
     */
98
    junk: object;
99
    /**
100
     * The data of the '_PMX' chunk.
101
     * @type {!Object<string, *>}
102
     */
103
    _PMX: object;
104
105
    /**
106
     * @param {Uint8Array=} [wavBuffer=null] A wave file buffer.
107
     * @throws {Error} If no 'RIFF' chunk is found.
108
     * @throws {Error} If no 'fmt ' chunk is found.
109
     * @throws {Error} If no 'data' chunk is found.
110
     */
111
    constructor(wavBuffer?: Uint8Array);
112
113
    /**
114
     * Return the samples packed in a Float64Array.
115
     * @param {boolean=} [interleaved=false] True to return interleaved samples,
116
     *   false to return the samples de-interleaved.
117
     * @param {Function=} [OutputObject=Float64Array] The sample container.
118
     * @return {!(Array|TypedArray)} the samples.
119
     */
120
    getSamples(interleaved?: boolean, OutputObject?: Function): Float64Array;
121
122
    /**
123
     * Return the sample at a given index.
124
     * @param {number} index The sample index.
125
     * @return {number} The sample.
126
     * @throws {Error} If the sample index is off range.
127
     */
128
    getSample(index: number): number;
129
130
    /**
131
     * Set the sample at a given index.
132
     * @param {number} index The sample index.
133
     * @param {number} sample The sample.
134
     * @throws {Error} If the sample index is off range.
135
     */
136
    setSample(index: number, sample: number): void;
137
138
    /**
139
     * Set up the WaveFileCreator object based on the arguments passed.
140
     * Existing chunks are reset.
141
     * @param {number} numChannels The number of channels.
142
     * @param {number} sampleRate The sample rate.
143
     *    Integers like 8000, 44100, 48000, 96000, 192000.
144
     * @param {string} bitDepthCode The audio bit depth code.
145
     *    One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64'
146
     *    or any value between '8' and '32' (like '12').
147
     * @param {!(Array|TypedArray)} samples The samples.
148
     * @param {Object=} options Optional. Used to force the container
149
     *    as RIFX with {'container': 'RIFX'}
150
     * @throws {Error} If any argument does not meet the criteria.
151
     */
152
    fromScratch(
153
      numChannels: number,
154
      sampleRate: number,
155
      bitDepthCode: string,
156
      samples:
157
        | Array<number>
158
        | Array<Array<number>>
159
        | ArrayLike<any>
160
        | Array<ArrayLike<any>>,
161
      options?: object
162
    ): void;
163
164
    /**
165
     * Set up the WaveFileCreator object from an mpeg buffer and/or optional info.
166
     * @param {!Uint8Array} mpegBuffer The buffer.
167
     * @param {Object=} info Optional Mpeg info such as version, layer,  etc.
168
     * @throws {Error} If the mpeg file cannot be parsed
169
     */
170
    fromMpeg(mpegBuffer: Uint8Array, info?: object): void;
171
172
    /**
173
     * Set up the WaveFileParser object from a byte buffer.
174
     * @param {!Uint8Array} wavBuffer The buffer.
175
     * @param {boolean=} [samples=true] True if the samples should be loaded.
176
     * @throws {Error} If container is not RIFF, RIFX or RF64.
177
     * @throws {Error} If format is not WAVE.
178
     * @throws {Error} If no 'fmt ' chunk is found.
179
     * @throws {Error} If no 'data' chunk is found.
180
     */
181
    fromBuffer(bytes: Uint8Array, samples?: boolean): void;
182
183
    /**
184
     * Return a byte buffer representig the WaveFileParser object as a .wav file.
185
     * The return value of this method can be written straight to disk.
186
     * @return {!Uint8Array} A wav file.
187
     * @throws {Error} If bit depth is invalid.
188
     * @throws {Error} If the number of channels is invalid.
189
     * @throws {Error} If the sample rate is invalid.
190
     */
191
    toBuffer(): Uint8Array;
192
193
    /**
194
     * Use a .wav file encoded as a base64 string to load the WaveFile object.
195
     * @param {string} base64String A .wav file as a base64 string.
196
     * @throws {Error} If any property of the object appears invalid.
197
     */
198
    fromBase64(base64String: string): void;
199
200
    /**
201
     * Return a base64 string representig the WaveFile object as a .wav file.
202
     * @return {string} A .wav file as a base64 string.
203
     * @throws {Error} If any property of the object appears invalid.
204
     */
205
    toBase64(): string;
206
207
    /**
208
     * Return a DataURI string representig the WaveFile object as a .wav file.
209
     * The return of this method can be used to load the audio in browsers.
210
     * @return {string} A .wav file as a DataURI.
211
     * @throws {Error} If any property of the object appears invalid.
212
     */
213
    toDataURI(): string;
214
215
    /**
216
     * Use a .wav file encoded as a DataURI to load the WaveFile object.
217
     * @param {string} dataURI A .wav file as DataURI.
218
     * @throws {Error} If any property of the object appears invalid.
219
     */
220
    fromDataURI(dataURI: string): void;
221
222
    /**
223
     * Force a file as RIFF.
224
     */
225
    toRIFF(): void;
226
227
    /**
228
     * Force a file as RIFX.
229
     */
230
    toRIFX(): void;
231
232
    /**
233
     * Change the bit depth of the samples.
234
     * @param {string} newBitDepth The new bit depth of the samples.
235
     *    One of '8' ... '32' (integers), '32f' or '64' (floats)
236
     * @param {boolean=} [changeResolution=true] A boolean indicating if the
237
     *    resolution of samples should be actually changed or not.
238
     * @throws {Error} If the bit depth is not valid.
239
     */
240
    toBitDepth(newBitDepth: string, changeResolution?: boolean): void;
241
242
    /**
243
     * Convert the sample rate of the file.
244
     * @param {number} sampleRate The target sample rate.
245
     * @param {Object=} options The extra configuration, if needed.
246
     */
247
    toSampleRate(samples: number, options?: object): void;
248
249
    /**
250
     * Encode a 16-bit wave file as 4-bit IMA ADPCM.
251
     * @throws {Error} If sample rate is not 8000.
252
     * @throws {Error} If number of channels is not 1.
253
     */
254
    toIMAADPCM(): void;
255
256
    /**
257
     * Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file.
258
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
259
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
260
     */
261
    fromIMAADPCM(bitDepthCode?: string): void;
262
263
    /**
264
     * Encode a 16-bit wave file as 8-bit A-Law.
265
     */
266
    toALaw(): void;
267
268
    /**
269
     * Decode a 8-bit A-Law wave file into a 16-bit wave file.
270
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
271
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
272
     */
273
    fromALaw(bitDepthCode?: string): void;
274
275
    /**
276
     * Encode 16-bit wave file as 8-bit mu-Law.
277
     */
278
    toMuLaw(): void;
279
280
    /**
281
     * Decode a 8-bit mu-Law wave file into a 16-bit wave file.
282
     * @param {string=} [bitDepthCode='16'] The new bit depth of the samples.
283
     *  One of '8' ... '32' (integers), '32f' or '64' (floats).
284
     */
285
    fromMuLaw(bitDepthCode?: string): void;
286
287
    /**
288
     * Write a RIFF tag in the INFO chunk. If the tag do not exist,
289
     * then it is created. It if exists, it is overwritten.
290
     * @param {string} tag The tag name.
291
     * @param {string} value The tag value.
292
     * @throws {Error} If the tag name is not valid.
293
     */
294
    setTag(tag: string, value: string): void;
295
296
    /**
297
     * Return the value of a RIFF tag in the INFO chunk.
298
     * @param {string} tag The tag name.
299
     * @return {?string} The value if the tag is found, null otherwise.
300
     */
301
    getTag(tag: string): string | null;
302
303
    /**
304
     * Return a Object<tag, value> with the RIFF tags in the file.
305
     * @return {!Object<string, string>} The file tags.
306
     */
307
    listTags(): object;
308
309
    /**
310
     * Remove a RIFF tag in the INFO chunk.
311
     * @param {string} tag The tag name.
312
     * @return {boolean} True if a tag was deleted.
313
     */
314
    deleteTag(tag: string): boolean;
315
316
    /**
317
     * Create a cue point in the wave file.
318
     * @param {!Object<string, *>} pointData The data of the cue point.
319
     */
320
    setCuePoint(pointData: object): void;
321
322
    /**
323
     * Remove a cue point from a wave file.
324
     * @param {number} index the index of the point. First is 1,
325
     *  second is 2, and so on.
326
     */
327
    deleteCuePoint(index: number): void;
328
329
    /**
330
     * Return an array with all cue points in the file, in the order they appear
331
     * in the file.
332
     * Objects representing cue points/regions look like this:
333
     *   {
334
     *     position: 500, // the position in milliseconds
335
     *     label: 'cue marker 1',
336
     *     end: 1500, // the end position in milliseconds
337
     *     dwName: 1,
338
     *     dwPosition: 0,
339
     *     fccChunk: 'data',
340
     *     dwChunkStart: 0,
341
     *     dwBlockStart: 0,
342
     *     dwSampleOffset: 22050, // the position as a sample offset
343
     *     dwSampleLength: 3646827, // the region length as a sample count
344
     *     dwPurposeID: 544106354,
345
     *     dwCountry: 0,
346
     *     dwLanguage: 0,
347
     *     dwDialect: 0,
348
     *     dwCodePage: 0,
349
     *   }
350
     * @return {!Array<Object>}
351
     */
352
    listCuePoints(): Array<object>;
353
354
    /**
355
     * Update the label of a cue point.
356
     * @param {number} pointIndex The ID of the cue point.
357
     * @param {string} label The new text for the label.
358
     */
359
    updateLabel(pointIndex: number, label: string): void;
360
361
    /**
362
     * Set the value of the iXML chunk.
363
     * @param {string} iXMLValue The value for the iXML chunk.
364
     * @throws {TypeError} If the value is not a string.
365
     */
366
    setiXML(iXMLValue: string): void;
367
368
    /**
369
     * Return the value of the iXML chunk.
370
     * @return {string} The contents of the iXML chunk.
371
     */
372
    getiXML(): string;
373
374
    /**
375
     * Set the value of the _PMX chunk.
376
     * @param {string} _PMXValue The value for the _PMX chunk.
377
     * @throws {TypeError} If the value is not a string.
378
     */
379
    set_PMX(_PMXValue: string): void;
380
381
    /**
382
     * Get the value of the _PMX chunk.
383
     * @return {string} The contents of the _PMX chunk.
384
     */
385
    get_PMX(): string;
386
  }
387
}
388